package cl.uchile.sketchpad.persistance.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cl.uchile.sketchpad.persistance.model.UploadedFile;

@Repository
public class UploadedFileDaoImpl implements UploadedFileDao {
	
	@PersistenceContext
	private EntityManager em; 

	@Override
	@Transactional(readOnly = true)
	public List<UploadedFile> getAll() {
		TypedQuery<UploadedFile> q = em.createQuery("from UploadedFile", UploadedFile.class);
		return q.getResultList();
	}

	@Override
	public UploadedFile findById(Long id) {
		return em.find(UploadedFile.class, id);
	}

	@Override
	@Transactional
	public void persist(UploadedFile uploadedFile) {
		em.persist(uploadedFile);
	}

	@Override
	public void remove(UploadedFile uploadedFile) {
		em.remove(uploadedFile);
	}

}
